﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;
using System.Collections.Generic;

namespace Xn4Sl.Framework.Graphics
{
    /// <summary>
    /// Represents a collection of Texture objects.
    /// </summary>
    public sealed class TextureCollection
    {
        /// <summary>
        /// List of collected textures.
        /// </summary>
        private List<Texture2D> textures = new List<Texture2D>();

        /// <summary>
        /// Global zindex value for collected textures.
        /// </summary>
        private int zIndex = 0;
        public int ZIndex
        {
            get
            {
                return this.zIndex;
            }
            set
            {
                this.zIndex = value;
            }
        }

        /// <summary>
        /// Gets or sets the Texture at the specified sampler number.
        /// </summary>
        /// <param name="index">Texture index.</param>
        /// <returns>The Texture at the specified index.</returns>
        public Texture2D this[int index] 
        { 
            get 
            { 
                return this.textures[index];
            } 
            set 
            {
                this.textures[index] = value;
            } 
        }

        /// <summary>
        /// Gets the number of textures actually contained in the collection.
        /// </summary>
        internal int Count
        {
            get
            {
                return this.textures.Count;
            }
        }

        /// <summary>
        /// Determines whether a texture is in the collection.
        /// </summary>
        /// <param name="texture">The texture to locate in collection.</param>
        /// <returns>true if item is found in the collection; false otherwise.</returns>
        internal bool Contains(Texture2D texture)
        {
            return this.textures.Contains(texture);
        }

        /// <summary>
        /// Adds a texture to the end of the collection.
        /// </summary>
        /// <param name="texture">The texture to be added.</param>
        internal void Add(Texture2D texture)
        {
            //this.textures.Add(texture);
            texture.ZIndex = this.zIndex++;
        }

        /// <summary>
        /// Removes the element at the specified index of the collection.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        internal void RemoveAt(int index)
        {
            this.textures.RemoveAt(index);
        }

        /// <summary>
        /// Removes all elements from the collection.
        /// </summary>
        internal void Clear()
        {
            //this.textures.Clear();
            this.zIndex = 0;
        }
    }
}
